//
//  FKMyCollectCell.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/28.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKMyCollectCell.h"

@interface FKMyCollectCell ()

/** 商品图片*/
@property (nonatomic, weak) UIImageView *picView;
/** 商品名称*/
@property (nonatomic, weak) UILabel *nameLabel;

@property (nonatomic, weak) UILabel *specLabel;
/** 商品价格*/
@property (nonatomic, weak) UILabel *priceLabel;
@property (nonatomic, weak) UILabel *marketLabel;

@end

@implementation FKMyCollectCell

- (void)setupSubviews
{
    [super setupSubviews];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *picView = [[UIImageView alloc] init];
    [self.contentView addSubview:picView];
    self.picView = picView;
    
    UILabel *nameLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor333333];
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    nameLabel.numberOfLines = 2;
    
    UILabel *specLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:specLabel];
    self.specLabel = specLabel;
    
    UILabel *priceLabel = [UILabel fk_labelWithFont:fk_adjustFont(15) textColor:fkMainColor];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *marketLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColorB2B2B2];
    [self.contentView addSubview:marketLabel];
    self.marketLabel = marketLabel;
    
    UIButton *deleteBtn = [UIButton fk_btnWithTarget:self action:@selector(deleteBtnClicked) img:[UIImage imageNamed:@"collection_delete"]];
    [self.contentView addSubview:deleteBtn];
    deleteBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    deleteBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    
    [picView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(fk_adjustW(90));
        make.left.offset(12);
        make.centerY.offset(0);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(picView);
        make.left.equalTo(picView.mas_right).offset(fk_adjustW(12));
        make.right.offset(-12);
    }];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(picView);
        make.left.equalTo(nameLabel);
    }];
    [marketLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(priceLabel);
        make.left.equalTo(priceLabel.mas_right).offset(fk_adjustW(10));
    }];
    [specLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel);
        make.bottom.equalTo(priceLabel.mas_top).offset(fk_adjustW(-15));
    }];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(30);
        make.right.equalTo(nameLabel);
        make.bottom.equalTo(priceLabel);
    }];
}

- (void)deleteBtnClicked
{
    if (self.deleteBlock) {
        self.deleteBlock(self.data);
    }
}

- (void)setData:(id)data
{
    [super setData:data];
    
    [self.picView sd_setImageWithURL:[NSURL URLWithString:data[@"img"]] placeholderImage:kPlaceholder_1x1];
    self.nameLabel.text = data[@"title"];
//    self.specLabel.text =
    self.priceLabel.text = fkFORMAT(@"￥%@", data[@"price"]);
    self.priceLabel.attributedText = [self.priceLabel.text fk_addAttributeStyle:@"￥" color:fkMainColor font:fk_adjustFont(12)];
    self.marketLabel.text = fkFORMAT(@"￥%@", data[@"marketprice"]);
    [self.marketLabel fk_addMiddleLine:fkColorB2B2B2];
}


@end
